home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / DPShaders / DPWallPaper.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  1.7 KB  |  62 lines

  1.  
  2. #define NCELLS 10
  3. #define CELLSIZE (1/NCELLS)
  4. #define snoise(s,t)    (2*noise((s),(t))-1)
  5.  
  6. surface
  7. DPWallPaper(
  8.     uniform float Ka = 1;
  9.     uniform float Kd = 1;
  10.     uniform color starcolor = color (1.0000,0.5161,0.0000);
  11.     uniform float npoints = 5;
  12.      )
  13. {
  14.     color Ct;
  15.     point Nf;
  16.     float ss, tt, angle, r, a, in_out;
  17.     float sctr, tctr, scell, tcell;
  18.     float scellctr, tcellctr;
  19.     float i, j;
  20.     uniform float rmin = 0.01, rmax = 0.03;
  21.     uniform float starangle = 2*PI/npoints;
  22.     uniform point p0 = rmax*(cos(0),sin(0),0);
  23.     uniform point p1 = rmin*
  24.         (cos(starangle/2),sin(starangle/2),0);
  25.     uniform point d0 = p1 - p0;
  26.     point d1;
  27.  
  28.     scellctr = floor(s*NCELLS);
  29.     tcellctr = floor(t*NCELLS);
  30.     in_out = 0;
  31.  
  32.     for (i = -1; i <= 1; i += 1) {
  33.         for (j = -1; j <= 1; j += 1) {
  34.         scell = scellctr + i;
  35.         tcell = tcellctr + j;
  36.         if (float noise(3*scell-9.5,7*tcell+7.5) < 0.55) {
  37.                 sctr = CELLSIZE * (scell + 0.5
  38.                      + 0.6 * snoise(scell+0.5, tcell+0.5));
  39.                 tctr = CELLSIZE * (tcell + 0.5
  40.                      + 0.6 * snoise(scell+3.5, tcell+8.5));
  41.                 ss = s - sctr;
  42.                 tt = t - tctr;
  43.             
  44.                 angle = atan(ss, tt) + PI;
  45.                 r = sqrt(ss*ss + tt*tt);
  46.                 a = mod(angle, starangle)/starangle;
  47.             
  48.                 if (a >= 0.5)
  49.                     a = 1 - a;
  50.                 d1 = r*(cos(a), sin(a),0) - p0;
  51.                 in_out += step(0, zcomp(d0^d1));
  52.             }
  53.         }
  54.     }
  55.     Ct = mix(Cs, starcolor, step(0.5,in_out));
  56.  
  57.     /* "matte" reflection model */
  58.     Nf = normalize(faceforward(N, I));
  59.     Oi = Os;
  60.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  61. }
  62.